package main

import (
	"crontab/master"
	"flag"
	"log"
	"os"
	"time"
)

var (
	configFile string
)

// 初始化参数
func initArgs() {
	flag.StringVar(&configFile,"config","./master/master.json","传入master.json的配置文件路径")
	flag.Parse()
}

func main() {
	var (
		err error
	)

	initArgs()
	err = master.InitConfig(configFile)
	if err != nil {
		path,_ := os.Getwd()
		log.Printf("当前目录 " + path)
		log.Printf("初始化config配置失败" + err.Error())
		return
	}

	err = master.InitEtcd()
	if err != nil {
		log.Printf("初始化etcd失败 " + err.Error())
		return
	}

	if err = master.InitLogMgr();err != nil {
		log.Printf("初始化mongoDb失败" + err.Error())
		return
	}
	// 初始化worker节点结构体
	master.InitWorkerMgr()

	err = master.InitHttpServer()
	if err != nil {
		log.Printf("启动http服务错误" + err.Error())
		return
	}
	log.Printf("启动成功")
	for {
		time.Sleep(time.Second * 60)
	}

}
